using System;
using System.Xml;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;

namespace ScenarioFramework.Modules.FormHelper
{
	//*********************************************************************
	//
	// XMLFormHelper Class
	//
	// The XMLFormHelper class represents a collection base of XMLActions
	// Its imports methods from bOSdotNET.XML.Data.XMLObjectSet like get set and add
	// XMLFormHelper Has no fields
	//
	//*********************************************************************

	public class XMLFormActions : bOSdotNET.XML.Data.XMLObjectSet
	{
		public const string MAIN_NODE	= "FormHelper";

		public XMLFormActions()
		{
			this.Init();
		}

		public XMLFormActions(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		override public void Init()
		{
			this.RemoveAll();
		}

		override public void Parse(System.Xml.XmlNode nodeList)
		{
			this.Init();

			System.Xml.XmlNode node;

			for ( int i=0; i<nodeList.ChildNodes.Count;i++)
			{
				node = nodeList.ChildNodes[i];

				switch ( node.Name) 
				{
					case XMLActions.MAIN_NODE:
						this.Add ( new XMLActions(node));
						break;
				}
			}

		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode XMLNode = new bOSdotNET.XML.XMLNode(XMLFormActions.MAIN_NODE);

			for ( int i=0; i<this.Count;i++)
			{
				XMLNode.AddNode ( this[i].GetXMLNode() );
			}

			return XMLNode;
		}

		public XMLActions Get(string sName)
		{
			XMLActions actions;

			for ( int i=0; i<this.List.Count; i++)
			{
				actions = (XMLActions)this.List[i];
				if ( actions.sName == sName )
				{
					return actions;
				}
			}

			throw new Exception.XMLActionNotFound();
		}

		/** Method for checking an ation in collection **/
		public bool AlmostIn(XMLFormActions vValues)
		{
			XMLActions leftActions;
			XMLActions rightActions;

			for ( int i=0; i<this.List.Count; i++)
			{
				leftActions = (XMLActions)this.List[i];

				try
				{
					rightActions = vValues.Get(leftActions.sName);
				}
				catch (Exception.XMLActionsNotFound)
				{
					return false;
				}
			}
			
			return true;
		}

		/** Method for checking an action in collection **/
		public bool AlmostInByName (string sName)
		{
			XMLActions Actions;

			for ( int i=0; i<this.List.Count; i++)
			{
				Actions = (XMLActions)this.List[i];

				if (Actions.sName == sName)
				{
					return true;
				}
			}
			
			return false;
		}
	}
}
